import 'package:flutter/material.dart';
import 'lc_tableview_session_item.dart';
import 'lc_typedef.dart';

class LCTableView extends StatelessWidget {
  /// session
  final int numberOfSessions;
  final double sessionHeaderHeight;
  final IndexedWidgetBuilder viewForHeaderInSection;
  final DidClickedSessionAtIndex didClickedSessionAtIndex;

  /// cell
  final NumberOfRowsInSection numberOfRowsInSection;
  final IndexPathWidgetBuilder cellForRowAtIndexPath;
  final DidClickedCellAtIndexPath didClickedCellAtIndexPath;

  LCTableView.builder({
    /// sessionHeader
    this.numberOfSessions = 0,
    this.sessionHeaderHeight = 45.0,
    this.viewForHeaderInSection,
    this.didClickedSessionAtIndex,

    /// cell
    @required this.numberOfRowsInSection,
    @required this.cellForRowAtIndexPath,
    this.didClickedCellAtIndexPath,
  });

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemBuilder: (ctx, index) {
        return LCTableViewSessionItem(
          sessionIndex: index,
          sessionHeaderHeight: sessionHeaderHeight,
          viewForHeaderInSection: viewForHeaderInSection,
          didClickedSessionAtIndex: didClickedSessionAtIndex,

          numberOfRowsInSection: numberOfRowsInSection,
          cellForRowAtIndexPath: cellForRowAtIndexPath,
          didClickedCellAtIndexPath: didClickedCellAtIndexPath,
        );
      },
      separatorBuilder: (ctx, index) {
        return Divider(
          color: Color.fromARGB(255, 221, 221, 221),
          height: 1,
        );
      },
      itemCount: numberOfSessions,
    );
  }
}
